package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/dish")
@Slf4j
@Api(tags = "菜品管理功能")
public class DishController {
    @Autowired
    private DishService dishService;

    /**
     * @return Result<PageResult>
     * @throws
     * @description 分页查询菜品的功能
     * @author Administrator
     * @param[1] dto
     * @time 2023/11/27 23:57
     */
    @GetMapping("/page")
    @ApiOperation("分页查询菜品的功能")
    public Result<PageResult> pageSelectDish(DishPageQueryDTO dto) {

        log.info("正在执行分页查询菜品的功能......查询的菜品信息为:{}", dto);

        PageResult p = dishService.pageSelectDish(dto);

        return Result.success(p);

    }

    /**
     * @return Result<DishVO>
     * @throws
     * @description 根据id查询菜品的功能
     * @author Administrator
     * @param[1] id
     * @time 2023/11/27 23:58
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询菜品的功能")
    public Result<DishVO> selectDishById(@PathVariable Long id) {

        log.info("正在执行根据id查询菜品的功能........id为:{}", id);

        DishVO dishVO = dishService.selectDishById(id);

        return Result.success(dishVO);

    }

    /**
     * @return Result<List < Dish>>
     * @throws
     * @description 根据分类id查询菜品
     * @author Administrator
     * @param[1] id
     * @time 2023/11/27 23:58
     */
    @GetMapping("/list")
    @ApiOperation("根据分类id查询菜品")
    public Result<List<Dish>> selectDishByCategoryId(Long categoryId) {

        log.info("正在执行根据分类id查询菜品的功能........分类id为:{}", categoryId);

        List<Dish> dishes = dishService.selectDishByCategoryId(categoryId);

        return Result.success(dishes);

    }

    /**
     * @return Result
     * @throws
     * @description 新添菜品的功能
     * @author Administrator
     * @param[1] dto
     * @time 2023/11/27 23:58
     */
    @PostMapping
    @ApiOperation("新添菜品的功能")
    public Result insertDish(@RequestBody DishDTO dto) {


        log.info("正在执行新添菜品的功能......新添的菜品信息为:{}", dto);

        dishService.insertDish(dto);

        return Result.success();

    }

    /**
     * @return Result
     * @throws
     * @description 菜品启用/禁用功能
     * @author Administrator
     * @param[1] status
     * @param[2] id
     * @time 2023/11/28 15:54
     */

    @ApiOperation("菜品的起售及其停售功能")
    @PostMapping("/status/{status}")
    public Result statusStartOrStop(@PathVariable Integer status, Long id) {

        log.info("正在执行菜品的起售及其停售功能.........功能状态为:{},菜品id为:{}", status, id);


        dishService.statusStartOrStop(status, id);

        return Result.success();


    }


    /**
     * @return Result
     * @throws
     * @description 菜品的修改功能
     * @author Administrator
     * @param[1] dto
     * @time 2023/11/28 16:12
     */

    @ApiOperation("菜品的修改功能")
    @PutMapping
    public Result updateDish(@RequestBody DishDTO dto) {

        log.info("正在执行菜品的修改功能..............修改的菜品信息为:{}", dto);

        dishService.updateDish(dto);

        return Result.success();
    }
/**
 * @description 删除菜品的功能
 * @author Administrator
 * @param[1] ids
 * @throws
 * @return Result
 * @time 2023/11/28 17:25
 */
    @ApiOperation("删除菜品的功能")
    @DeleteMapping
    public Result deleteDish(@RequestParam List<Long> ids) {


        log.info("正在执行删除菜品的功能............删除的菜品信息为:{}", ids);

        dishService.deleteDish(ids);

        return Result.success();

    }

}
